package modelkontrol;

import java.util.List;

import hibernate.HibernatePasienUtil;
import model.MObat;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class KontrolObat {
	public void saveObat(MObat obat)
	{
		Session session = HibernatePasienUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		try {
			transaction = session.beginTransaction();
			session.save(obat);
			transaction.commit();
		} catch (HibernateException e) {
			transaction.rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
	}
	
	public MObat getObatById(String id){
		Session session = HibernatePasienUtil.getSessionFactory().openSession();
		Query query = session.createQuery("from MObat where id = :id");
		query.setParameter("id", id);
		return (MObat) query.uniqueResult();
	}
}
